<?php

namespace App\Http\Middleware;

use App;
use Closure;

class LanguageMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $lang = $request->header('Language', 'ZH-CN');
        switch ($lang) {
            case 'EN-US':
                App::setLocale('en');
                break;
            case 'ZH-CN':
                App::setLocale('zn');
                break;
            default:
                App::setLocale('en');
                break;
        }

        return $next($request);
    }
}
